<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="路段id" prop="roadpartId">
        <el-input
          v-model="queryParams.roadpartId"
          placeholder="请输入路段id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="养护时间" prop="recordDate">
        <el-date-picker clearable
          v-model="queryParams.recordDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择养护时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="养护员工" prop="staffId">
        <el-input
          v-model="queryParams.staffId"
          placeholder="请输入养护员工id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="维修类型" prop="sysFixType">
        <el-select v-model="queryParams.sysFixType" placeholder="请选择维修类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_fix_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="抽检" prop="checkr">
        <el-select v-model="queryParams.checkr" placeholder="请选择抽检" clearable>
          <el-option
            v-for="dict in dict.type.sys_list_checker"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-circle-check"
          size="mini"
          @click="allchecked"
      
        >一键已检</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:onlyforchecker:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:onlyforchecker:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-refresh-right"
          size="mini"
          @click="randomselect"
          
        >随机抽检</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:onlyforchecker:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="onlyforcheckerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="养护记录id" align="center" prop="recordId" />
      <el-table-column label="养护问题记录" align="center" prop="problem" />
      <el-table-column label="路段id" align="center" prop="roadpartId" />
      <el-table-column label="养护时间" align="center" prop="recordDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="养护员工" align="center" prop="staffId" />
      <el-table-column label="维修类型" align="center" prop="sysFixType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_fix_type" :value="scope.row.sysFixType"/>
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="picture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.picture" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="抽检" align="center" prop="checkr">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_list_checker" :value="scope.row.checkr"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:onlyforchecker:edit']"
          >修改</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:onlyforchecker:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改养护抽检对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="更改抽检状态为" prop="checkr">
          <el-select v-model="form.checkr" placeholder="请选择抽检类型">
            <el-option
              v-for="dict in dict.type.sys_list_checker"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOnlyforchecker, getOnlyforchecker, delOnlyforchecker, addOnlyforchecker, updateOnlyforchecker } from "@/api/system/onlyforchecker";

export default {
  name: "Onlyforchecker",
  dicts: ['sys_fix_type', 'sys_list_checker'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 养护抽检表格数据
      onlyforcheckerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roadpartId: null,
        recordDate: null,
        staffId: null,
        sysFixType: null,
        checkr: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
       /**随机抽检按钮操作 */
        randomselect(){
          var randomroadId=this.total;
          this.queryParams.roadpartId=parseInt(Math.random()*(randomroadId-1+1)+1);
          this.getList;

        },
    /**框选为已检查 */
    allchecked(){
      this.reset();
    },
    /** 查询养护抽检列表 */
    getList() {
      this.loading = true;
      listOnlyforchecker(this.queryParams).then(response => {
        this.onlyforcheckerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordId: null,
        problem: null,
        roadpartId: null,
        recordDate: null,
        staffId: null,
        sysFixType: null,
        picture: null,
        checkr: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加养护抽检";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recordId = row.recordId || this.ids
      getOnlyforchecker(recordId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改养护抽检";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordId != null) {
            updateOnlyforchecker(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOnlyforchecker(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal.confirm('是否确认删除养护抽检编号为"' + recordIds + '"的数据项？').then(function() {
        return delOnlyforchecker(recordIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/onlyforchecker/export', {
        ...this.queryParams
      }, `onlyforchecker_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
